/**
 * Created by oneminute on 7/17/14.
 */

var lz = require("../lib/utils/modules")();

exports.post = function (_req, _res, _opts, _callback) {
    var user = _opts.user;
    if (user) {
        var photo = _opts.photo;
        lz.Logger.debug("用户头像文件: ", photo.path);
        lz.ImageManager.handleUserPhoto(photo, function (_err, _photo) {
            if (_photo) {
                user.photo = _photo;
                user.save({saveAll: false}, function(_err, _user) {
                    _callback(null, user, {photo: _photo});
                });
            } else {
                _callback(_err, user);
            }
        });
    } else {
        _callback(lz.Config.errors.getError(lz.Config.errors.REQUEST_TEMPUSER_ERROR));
    }
};
